package com.kanshu.ksgb.fastread.doudou.common.net.bean;

import com.kanshu.ksgb.fastread.doudou.common.net.exception.InvalidDataException;

/**
 * 网络请求结果基类
 * Created by wcy on 2017/4/22.
 */
public class BaseResult<T> {

    public BaseResultBean<T> result;

    @Override
    public String toString() {
        return "BaseResult{" +
                "result=" + result +
                '}';
    }

    public T data() throws InvalidDataException {
        if (result != null && result.status != null) {
            if (result.status.code == 0) {
                return result.data;
            } else {
                throw new InvalidDataException(result.status.code, result.status.msg);
            }
        } else {
            //Constants.ErrCode.NoData
            throw new InvalidDataException(-11282, "no data");
        }
    }
    /**
     * 判断非空数据
     * @param result
     * @return
     */
    public static boolean isNotNull(BaseResult result) {
        return result != null && result.result != null;
    }
}
